﻿using Cloud.BLL;
using Cloud.Model;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Three_Managerment_P0500_List_yq : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["users"] == null)
            {
                Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
            }
            if (!IsPostBack)
            {
                bind();
                bind2();
                //this.bianhao.DataSource = ProblemManager.Bm1_blz(((USER_INFO)Session["users"]).DEPARTMENT);
                //this.bianhao.DataTextField = "appealid";
                //this.bianhao.DataValueField = "id";
                //this.bianhao.DataBind();
                //this.bianhao.Items.Insert(0, new ListItem("--请选择--", "0"));
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    protected void AspNetPager2_PageChanged(object sender, EventArgs e)
    {
        try
        {
            if (Session["users"] == null)
            {
                Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
            }
            bind2();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }


    public void bind()
    {
        try
        {
            if (Session["users"] == null)
            {
                Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
            }
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from problem where current_ld=1 and ( handle_type = 1 or handle_type = 2 ) and islook1 = 1 and zrdwid='" + ((USER_INFO)Session["users"]).DEPARTMENT + "' order by id desc", connection);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            AspNetPager1.PageSize = 10;//设置分页大小 
            AspNetPager1.RecordCount = ProblemManager.Bm1_blz(((USER_INFO)Session["users"]).DEPARTMENT).Count;//设置总数据条数 
            sda.Fill(ds, AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1), AspNetPager2.PageSize, "yq");//固定不变的 
            repeater1.DataSource = ds.Tables["yq"];
            repeater1.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }


    public void bind2()
    {
        try
        {
            if (Session["users"] == null)
            {
                Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
            }
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from yqsq where bm1_type=1 and bm2_type=0 and zrdwid='" + ((USER_INFO)Session["users"]).DEPARTMENT + "'", connection);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            AspNetPager2.PageSize = 10;//设置分页大小 
            AspNetPager2.RecordCount = YqsqManager.bm2_yq_list(((USER_INFO)Session["users"]).DEPARTMENT).Count;//设置总数据条数 
            sda.Fill(ds, AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1), AspNetPager2.PageSize, "yqsq");//固定不变的 
            repeater2.DataSource = ds.Tables["yqsq"];
            repeater2.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }
    protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("rep1") as Repeater;//找到里层的repeater对象
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
                int typeid = Convert.ToInt32(rowv["sjid"]); //获取填充子类的id 
                IList<Problem> sou = new List<Problem>();
                sou.Add(ProblemManager.FindById(typeid));
                rep.DataSource = sou;
                rep.DataBind();
            }
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("rep2") as Repeater;//找到里层的repeater对象
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
                int typeid = Convert.ToInt32(rowv["sjid"]); //获取填充子类的id 
                IList<Problem> sou = new List<Problem>();
                sou.Add(ProblemManager.FindById(typeid));
                rep.DataSource = sou;
                rep.DataBind();
            }
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("rep3") as Repeater;//找到里层的repeater对象
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
                int typeid = Convert.ToInt32(rowv["sjid"]); //获取填充子类的id 
                IList<Problem> sou = new List<Problem>();
                sou.Add(ProblemManager.FindById(typeid));
                rep.DataSource = sou;
                rep.DataBind();
            }


            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("rep5") as Repeater;//找到里层的repeater对象
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
                string typeid = Convert.ToString(rowv["zrdwid"]); //获取填充子类的id 
                IList<ZS_TYPEINFO> sou = new List<ZS_TYPEINFO>();
                sou.Add(ZS_TYPEINFOManager.FindById(typeid));
                rep.DataSource = sou;
                rep.DataBind();
            }
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("rep6") as Repeater;//找到里层的repeater对象
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
                string typeid = Convert.ToString(rowv["bldwid"]); //获取填充子类的id 
                IList<DW> sou = new List<DW>();
                sou.Add(DWManager.FindById(typeid));
                rep.DataSource = sou;
                rep.DataBind();
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    //事件状态
    public string sjzt(int i)
    {
        try
        {
            String zts = "";
            if (i == 0)
            {
                zts = "待办理";
            }
            else if (i == 1)
            {
                zts = "办理中";
            }
            else if (i == 2)
            {
                zts = "已办理";
            }
            else if (i == 3)
            {
                zts = "已办结";
            }
            else if (i == 4)
            {
                zts = "直办";
            }
            return zts;
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return "";
        }

    }

    //protected void bianhao_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    try
    //    {
    //        int id = Convert.ToInt32(this.bianhao.SelectedItem.Value);

    //        if (id == 0)
    //        {

    //        }
    //        else
    //        {
    //            Problem activity = ProblemManager.FindById(id);
    //            if (activity != null)
    //            {
    //                this.name.Value = activity.Appeal_name.ToString();
    //                this.tel.Value = activity.Appeal_tel.ToString();
    //                this.dalei.Value = Classification_Appeal1Manager.FindById(activity.Appeal_type_id).Name.ToString();
    //                this.xiaolei.Value = Classification_Appeal2Manager.FindById(activity.Xialei).Name.ToString();
    //                this.regtime.Value = activity.Regtime.ToString();
    //                this.xbtime.Value = activity.Xbtime.ToString();
    //                this.email.Value = activity.Appeal_email.ToString();
    //                this.title.Value = activity.Title.ToString();
    //                this.con.Value = activity.Context.ToString();
    //            }
    //            else
    //            {
    //                Response.Write("<script>alert('未查询到数据！')</script>");
    //            }

    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
    //        return;
    //    }

    //}
    protected void Unnamed_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.times.Value.Equals(""))
            {
                Response.Write("<script>alert('时间不能为空'); </script>");
                return;
            }
            if (Convert.ToDateTime(this.times.Value) < DateTime.Now)
            {
                Response.Write("<script>alert('请重新输入时间'); </script>");
                return;
            }

            if (Session["users"] == null)
            {
                Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
            }
            Yqsq activity = new Yqsq();

            activity.Bldwid = ((USER_INFO)Session["users"]).DEPARTMENT;
            activity.Bm0_type = 1;
            activity.Bm1_type = 1;
            activity.Bm2_type = 0;
            activity.Idopen = this.sjbh.Value;
            activity.Sjid = Convert.ToInt32(this.id.Value);
            activity.Times = Convert.ToDateTime(this.times.Value);
            activity.Zrdwid = DWManager.FindById(((USER_INFO)Session["users"]).DEPARTMENT).SJDW.Equals("") ? DWManager.FindById(((USER_INFO)Session["users"]).DEPARTMENT).DWBH : DWManager.FindById(((USER_INFO)Session["users"]).DEPARTMENT).SJDW;


            if (YqsqManager.Save(activity) > 0)
            {

                Problem_historic2 his = new Problem_historic2();
                his.Blyj = "";
                his.Title = "申请延期 ";
                his.Bm2 = "";
                his.Evente = 7;
                his.Idopen = this.sjbh.Value;


                his.Bm1 = ((USER_INFO)Session["users"]).DEPARTMENT;
                his.Item1 = 0;
                his.Item2 = "";
                his.Item3 = "";
                his.Name = ((USER_INFO)Session["users"]).USER_NAME;
                his.Times = DateTime.Now;
                his.Timese = Convert.ToDateTime(this.times.Value);


                Problem_historic2Manager.Save(his);

                Response.Write("<script>alert('提交成功');location.href='index.aspx'</script>");
            }
            else
            {
                Response.Write("<script>alert('提交失败');</script>");
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    protected void Unnamed_Click1(object sender, EventArgs e)
    {

        Response.Redirect("List_yq.aspx");
        //tab1.Style.Add("class","old");
        //this.bbbb.Style.Add("display", "block");
        //this.bbbb.Style.Add("tab1", "block");
        //this.bbbb.Style.Add("tab2", "none");
        //this.aaaa.Style.Add("display", "none");
    }
}